import 'package:flutterproject/mvvm/base/base_controller.dart';
import 'package:flutterproject/page/mine/children/my_group/data/my_group_bean.dart';
import 'package:flutterproject/util/address_manager.dart';
import 'package:flutterproject/util/dialog_toast/dialog_util.dart';
import 'package:flutterproject/util/dialog_toast/toast_util.dart';
import 'package:flutterproject/util/http/http_client.dart';
import 'package:flutterproject/util/http/http_exception.dart';
import 'package:get/get.dart';

class MyGroupController extends BaseController {
  HttpClient client = Get.find<HttpClient>();
  MyGroupBean? bean = MyGroupBean();

  @override
  void onReady() {
    super.onReady();
    getGroupData();
  }

  Future getGroupData() async {
    try {
      DialogUtil.showLoading();
      bean = await client.get<MyGroupBean>(AddressManager.groupData);
      update();
      return true;
    } on HttpException catch (e) {
      ToastUtil.showFailed(e.message);
      return false;
    } finally {
      DialogUtil.dismiss();
    }
  }

  String getVIPLevel(){
    switch (bean?.level ?? -1) {
      case 0:
        return "普通会员";
      case 1:
        return "VIP";
      case 2:
        return "代理商";
      case 3:
        return "区代理";
      case 4:
        return "市代理";
      case 5:
        return "大区总监";
      case 6:
        return "营销总监";
      case 7:
        return "营销总裁";
    }
    return "普通会员";
  }
}
